﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data;
using tmAsk.Common;

namespace tmAsk.Member
{
    public partial class Member : System.Web.UI.Page
    {

        tmAsk.Data.MakehtmlSQL SQL = new tmAsk.Data.MakehtmlSQL();

        DataTable dr;

        DataSet ds;
        
        protected HtmlGenericControl frame1;

        protected void Page_Load(object sender, EventArgs e)
        {
            function.CheckUserLogin();
            if (!string.IsNullOrEmpty(Request.QueryString["url"]))
            {
                HtmlControl frame1 = (HtmlControl)this.FindControl("ucIframe");
                frame1.Attributes["src"] = Request.QueryString["url"];
                //Page.ClientScript.RegisterStartupScript(GetType(), "script", "<script type=\"text/javascript\">document.frames['ucIframe'].location ='" + Request.QueryString["url"] + "';</script>");
            }

            string uid = function.Getcookies();

            string sql = "select * from b_user where u_id='" + uid + "'";

            if (SQL.GetList(sql).Tables[0].Rows.Count > 0)
            {

                dr = SQL.GetList(sql).Tables[0];
                
                ds = SQL.GetList("b_user", "u_id='" + uid + "'", "*");

                dr = SQL.GetList(1, "b_userLevel", "u_level =" + ds.Tables[0].Rows[0]["u_level"].ToString(), "u_id desc").Tables[0];
            }

            switch (Convert.ToInt32(dr.Rows[0]["u_level"]))
            {
                case 1:
                    myclass.Visible = false;
                    break;
                case 8:
                    myclass.Visible = true;
                    break;
                default:
                    myclass.Visible = false;
                    break;
            }

        }

        public string GetUserName()
        {
            return ds.Tables[0].Rows[0]["u_nickName"].ToString();
        }

        public string GetUserImg()
        {
            return ds.Tables[0].Rows[0]["u_img"].ToString();
        }

        public string GetUserLevel()
        {
            return dr.Rows[0]["u_title"].ToString();
        }

        public string GetUserAskNumber()
        {
            return ds.Tables[0].Rows[0]["u_askNumber"].ToString();
        }

        public string GetUserReviewNumber()
        {
            return ds.Tables[0].Rows[0]["u_reviewNumber"].ToString();
        }

        public string GetUserGoodNumber()
        {
            return ds.Tables[0].Rows[0]["u_goodNumber"].ToString();
        }

        public string GetMsgCount()
        {
            string count;
            string uid = function.Getcookies();

            string sql = "select u_id,u_nickName,u_img from b_user where u_id='" + uid + "'";

            System.Data.DataRow dr = SQL.GetList(sql).Tables[0].Rows[0];

            string sqlstr = "select m_id from B_msg where m_acceptuser=" + dr["u_id"].ToString() + " and m_isread=0";

            if (SQL.GetList(sqlstr).Tables[0].Rows.Count > 0)
            {
                count = "<a rel=\"answer\" href=\"message.aspx\" target=\"ucIframe\" class=\"newmsg\">您有<em>(" + SQL.GetList(sqlstr).Tables[0].Rows.Count.ToString() + ")</em>条新留言需要处理！</a>";
            }
            else
            {
                count = "<a rel=\"answer\" href=\"message.aspx\" target=\"ucIframe\" class=\"msgbox\">您没有留言要处理。</a>";
            }
            return count;
        }

    }
}